#!/bin/bash
declare DEPLOY_PATH="/sunyard/nginx/html-auxre/zdhr"

function get_input() {
  echo "#========中电惠融一键部署-开始========#"
  echo "请输入要部署的项目集合的数字编号:"
  echo "1、app  2、biz 3、fin"
  echo "4、app biz 5、app fin 6、biz fin"
  echo "7、app biz fin 8、退出"
  read -t 10 DEPLOY_NUM
  case $DEPLOY_NUM in
    "1")
      unzip2replace "app"
      ;;
    "2")
      unzip2replace "biz"
      ;;
    "3")
      unzip2replace "fin"
      ;;
    "4")
      unzip2replace "app"
      unzip2replace "biz"
      ;;
    "5")
      unzip2replace "app"
      unzip2replace "fin"
      ;;
    "6")
      unzip2replace "biz"
      unzip2replace "fin"
      ;;
    "7")
      unzip2replace "app"
      unzip2replace "biz"
      unzip2replace "fin"
      ;;
    *)
      exit 0
  esac
  echo "#========中电惠融一键部署-结束========#"
}

function unzip2replace() {
  echo "开始配置${1}端"
  sleep 3
  cd "${DEPLOY_PATH}/${1}"
  echo "开始备份${1}端"
  sleep 3
  if [ -d "dist" ];then
    echo "dist文件夹命中，开始备份"
    cur_date=`date '+%Y%m%d%H%M%S'`
    mv dist "dist-${cur_date}"
  else
    echo "dist文件夹未命中，无需备份"
  fi
  filename=`ls *.zip -t |head -n1|awk '{print $0}'`
  echo "开始解压${filename}到目录..."
  sleep 3
  unzip ${filename}
  echo "配置${1}端完成"
}

get_input